using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SimpleMessageQueue;
using slcl;

namespace slcl.TestClient.GUI
{
    public partial class AcountSettings : Form
    {
        MainDisplay Main;
        public AcountSettings(MainDisplay main)
        {
            Main = main;
            InitializeComponent();
        }

        public void Run()
        {
            Application.Run(this);
        }

        private void loginButton_Click(object sender, EventArgs e)
        {
            if (FirstNameTextBox.Text.Length < 2
                || lastNameTextBox.Text.Length < 2
                || passwordTextBox.Text.Length < 2)
            {
                MessageBox.Show("Please check your login and password. It's too short.");
                return;
            }
            Main.client.FirstName = FirstNameTextBox.Text;
            Main.client.LastName = lastNameTextBox.Text;
            Main.client.Password = passwordTextBox.Text;
            if (startLocationComboBox.SelectedItem != null)
            {
                if ((string)startLocationComboBox.SelectedItem == "Home"
                    || (string)startLocationComboBox.SelectedItem == "Last")
                {
                    // then pass it on to the start location target.
                }
                else
                {
                    int x = 128, y = 128, z = 32;
                    try
                    {
                        x = System.Convert.ToInt16(XPosTextBox.Text);
                        y = System.Convert.ToInt16(YPosTextBox.Text);
                        z = System.Convert.ToInt16(ZPosTextBox.Text);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Invalid coordinates.");
                    }
                    Main.client.StartLocation = Grid.StartLocation(startLocationComboBox.SelectedItem, x, y, z);
                }
            }
            CommandMessage Msg = new CommandMessage(Client.Commands.Login, null, new CommandMessage.AckCallback(LoginCallback));
            // build the start location if it's not Home or Last

            // ask client to log us in and call back to let us know success or failure.

            Main.MQueue.Send(Msg, Main.client);
        }    

        public void LoginCallback(AckMessage Msg)
        {

        }
    }
}